package com.canxi.games.app;

import cn.hutool.core.util.StrUtil;
import com.canxi.common.annotation.Log;
import com.canxi.common.annotation.RepeatSubmit;
import com.canxi.common.core.controller.BaseController;
import com.canxi.common.core.domain.PageQuery;
import com.canxi.common.core.domain.R;
import com.canxi.common.core.page.TableDataInfo;
import com.canxi.common.core.validate.EditGroup;
import com.canxi.common.enums.BusinessType;
import com.canxi.common.enums.OperatorType;
import com.canxi.games.domain.bo.CxGamesConfigBo;
import com.canxi.games.domain.vo.CxGamesConfigVo;
import com.canxi.games.service.ICxGamesConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 游戏配置
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/games/gamesConfig")
public class CxAppGamesConfigController extends BaseController {

    private final ICxGamesConfigService iCxGamesConfigService;

    /**
     * 查询游戏配置列表
     */
    @GetMapping("/list")
    public TableDataInfo<CxGamesConfigVo> list(CxGamesConfigBo bo, PageQuery pageQuery) {
        return iCxGamesConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取游戏配置详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<CxGamesConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iCxGamesConfigService.queryById(id));
    }


    /**
     * 修改游戏配置
     */
    @Log(title = "游戏配置", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE)
    @RepeatSubmit()
    @PutMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CxGamesConfigBo bo) {
        /**
         * 手机端只能修改图片
         */
        CxGamesConfigBo configBo = new CxGamesConfigBo();
        configBo.setId(bo.getId());
        if(StrUtil.isNotBlank(bo.getImg())){
            configBo.setImg(bo.getImg());
        }

        return toAjax(iCxGamesConfigService.updateByBo(configBo));
    }
}
